<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>proxy</title>
</head>
<body>
<script type="text/javascript">
    var add = function(){
        console.log('计算add')
        var totle = 0;
        for(var i = 0; i < arguments.length; i++){
            totle += arguments[i];
        }
        return totle;
    };
    var fnProxy = function(fn){
        var cache = [];
        return function(){
            var arg = Array.prototype.join.call(arguments,',');
            if(!(arg in cache)) cache[arg]=fn.apply(this,arguments);
                return cache[arg];
        }
    }

    var addProxy = fnProxy(add);

    console.log(addProxy(1,3))
    console.log(addProxy(1,2,3))








</script>
</body>
</html>